-- OldTerminal
-- Created by huanghr Apr/28/2016
-- 破旧的终端机(所有的特殊隐藏建筑都用)

-- 初始化
function initOldTerminal(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

                 -- 更新建筑访问
            AudioM.playFx("ui_open1");
            self:updateBuildingVisit();

            -- 还有怪物未死亡
            if not DungeonM.isAllMonsterDead() then
                self:openBuildingView(nil, -20, getLocStr("cave_hide_item_dialog"), getLocStr("btn_text_leave"));
                return;
            end

            local function okFunc()
                local pos = self.gridData:getPos();
                DungeonActionM.go("do_building_bonus", pos, nil, {
                    ["remainGrid"] = nil,
                    ["isSync"] = nil,
                    ["notComEvent"] = true
                });
            end
            self:openBuildingView(okFunc);
        end
    end

    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);

    -- 发光
    if self.gridData.need_shining == 1 then
        shiningEffect(self.icon, 70, 100);
    end
end

-- 操作终端机
function onShowBuildingBonus(self, bonusList, class)
    local tips = CaveHideItemM.getHideItemTips(class);

    splitAlert(tips);

    if bonusList.bonus and #table.keys(bonusList) > 0 then
        self:playBonusListEffect(bonusList);
    else
        -- 建筑消失
        playBuildingDisappear(self);
        EventMgr.fire(event.PLAYER_MOVE);
    end
end